package com.mig.coins.domain;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class Helper {

	public static String getInicioTrimestreActual() {
		Calendar cal = Calendar.getInstance();

		int month = cal.get(Calendar.MONTH);
		month = (month / 3) * 3;
		
		cal.set(Calendar.DAY_OF_MONTH, 1);
		cal.set(Calendar.MONTH, month);
		return date2String(cal.getTime());
	}

	public static String getFinalTrimestreActual() {
		Calendar cal = Calendar.getInstance();

		int day = 31;
		int month = cal.get(Calendar.MONTH);
		month = (month / 3) * 3;
		if (month == 3) 
			day = 30;

		cal.set(Calendar.DAY_OF_MONTH, day);
		cal.set(Calendar.MONTH, month+2);
		return date2String(cal.getTime());
	}
	
	public static String date2String(Date d) {
	    SimpleDateFormat formato = new SimpleDateFormat("yyyy-MM-dd");
		return formato.format(d);
	}
}
